package com.ruoyi.stuinfo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.stuinfo.domain.Stu;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.stuinfo.domain.StudentPunishments;
import com.ruoyi.stuinfo.service.IStudentPunishmentsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 惩戒查询Controller
 *
 * @author zc
 * @date 2025-05-16
 */
@RestController
@RequestMapping("/stuinfo/punishments")
public class StudentPunishmentsController extends BaseController
{
    @Autowired
    private IStudentPunishmentsService studentPunishmentsService;

    /**
     * 查询惩戒查询列表
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:punishments:list')")
    @GetMapping("/list")
    public TableDataInfo list(StudentPunishments studentPunishments)
    {
        String teacherId = getUsername();
        if("admin".equals(teacherId))
        {
            //管理员
            startPage();
            List<StudentPunishments> list = studentPunishmentsService.selectStudentPunishmentsList(studentPunishments);
            return getDataTable(list);
        }
        else
        {
            //学生
            startPage();
            List<StudentPunishments> list = studentPunishmentsService.selectStudentPunishmentsList_student(teacherId);
            return getDataTable(list);
        }

    }

    /**
     * 导出惩戒查询列表
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:punishments:export')")
    @Log(title = "惩戒查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentPunishments studentPunishments)
    {
        String teacherId = getUsername();
        if("admin".equals(teacherId))
        {
            //管理员
            List<StudentPunishments> list = studentPunishmentsService.selectStudentPunishmentsList(studentPunishments);
            ExcelUtil<StudentPunishments> util = new ExcelUtil<StudentPunishments>(StudentPunishments.class);
            util.exportExcel(response, list, "惩戒查询数据");
        }
        else
        {
            //学生
            List<StudentPunishments> list = studentPunishmentsService.selectStudentPunishmentsList_student(teacherId);
            ExcelUtil<StudentPunishments> util = new ExcelUtil<StudentPunishments>(StudentPunishments.class);
            util.exportExcel(response, list, "惩戒查询数据");
        }
    }

    /**
     * 获取惩戒查询详细信息
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:punishments:query')")
    @GetMapping(value = "/{punishmentId}")
    public AjaxResult getInfo(@PathVariable("punishmentId") Long punishmentId)
    {
        return success(studentPunishmentsService.selectStudentPunishmentsByPunishmentId(punishmentId));
    }

    /**
     * 新增惩戒查询
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:punishments:add')")
    @Log(title = "惩戒查询", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StudentPunishments studentPunishments)
    {
        return toAjax(studentPunishmentsService.insertStudentPunishments(studentPunishments));
    }

    /**
     * 修改惩戒查询
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:punishments:edit')")
    @Log(title = "惩戒查询", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StudentPunishments studentPunishments)
    {
        return toAjax(studentPunishmentsService.updateStudentPunishments(studentPunishments));
    }

    /**
     * 删除惩戒查询
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:punishments:remove')")
    @Log(title = "惩戒查询", businessType = BusinessType.DELETE)
	@DeleteMapping("/{punishmentIds}")
    public AjaxResult remove(@PathVariable Long[] punishmentIds)
    {
        return toAjax(studentPunishmentsService.deleteStudentPunishmentsByPunishmentIds(punishmentIds));
    }
}
